<?php
require_once '../sub/init.php';
require_once 'chkUadm.php';
if(!CRMQX('crm_talk_gh')){exit(noauth('暂无【外呼客户公海】权限'));}
require_once ZEAI.'cache/config_crm.php';
require_once ZEAI.'cache/udata.php';
$SQL = " AND (flag=1 OR flag=-2) AND kind<>4 AND admid>0 AND crm_ugrade=0 ";
$Skey  = trimhtml($Skey);
$Skey2 = trimhtml($Skey2);
if (ifint($Skey)){
	$SQL .= " AND (admid=$Skey OR hnid=$Skey OR hnid2=$Skey) ";
}elseif(!empty($Skey)){
	$SQL .= " AND (admname LIKE '%".$Skey."%' OR hnname LIKE '%".$Skey."%' OR hnname2 LIKE '%".$Skey."%' ) ";
}
//超管搜索按门店
if (ifint($agentid) && CRM_ADM)$SQL .= " AND agentid=$agentid";
//我的
if(!CRM_ADM)$SQL .= " AND (admid=".$session_uid." OR hnid=".$session_uid." OR hnid2=".$session_uid.") ";

if(!empty($Skey2)){
	if(ifmob($Skey2)){
		$SQL .= " AND mob= '".$Skey2."'";
	}elseif(ifint($Skey2)){
		$SQL .= " AND id = ".$Skey2;
	}else{
		$SQL .= " AND ( truename LIKE '%".$Skey2."%' OR nickname LIKE '%".$Skey2."%' OR mob LIKE '%".$Skey2."%' )";
	}
}
if (ifint($sex))$SQL .= " AND sex=$sex ";

$SORT = " ORDER BY id DESC ";

$rt = $db->query("SELECT id,grade,nickname,truename,sex,photo_s,mob,love,edu,birthday,agenttitle,kind,agentid,admid,admtime,admname,hnid,hnname,hnid2,hnname2,areatitle,area2title FROM ".__TBL_USER__." WHERE id NOT IN (SELECT uid FROM ".__TBL_TALK__.") ".$SQL."  ".$SORT." LIMIT ".$_ADM['admLimit']);
$total = $db->num_rows($rt);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="<?php echo HOST;?>/res/www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo HOST;?>/cache/udata.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo HOST;?>/res/select4.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="css/main.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
<link href="css/crm.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
</head>
<style>
.box{padding-top:10px;padding-bottom:20px;min-width:1000px}
</style>
<body>
<div class="box">
    <div class="topsearch">
        <form name="ZEAI_CN__form1" method="get" action="<?php echo SELF; ?>" style="margin-right:20px">
              <!--超管按门店查询-->
              <?php if(CRM_ADM){?>
              <?php
                $rt2=$db->query("SELECT id,title FROM ".__TBL_CRM_AGENT__." WHERE flag=1 ORDER BY px DESC,id DESC");
                $total2 = $db->num_rows($rt2);
                if ($total2 > 0) {?>
                    <select name="agentid" class="W150 size2 picmiddle">
                    <option value="">不限门店</option>
                    <?php
                    for($j=0;$j<$total2;$j++) {
                        $rows2 = $db->fetch_array($rt2,'num');
                        if(!$rows2) break;
                        $clss=($agentid==$rows2[0])?' selected':'';?><option value="<?php echo $rows2[0];?>"<?php echo $clss;?>><?php echo dataIO($rows2[1],'out');?></option><?php
                    }?>
                    </select>　<?php
                }}?>
              <!---->
            <input name="Skey" type="text" maxlength="25" class="input size2 W200" placeholder="按红娘ID/姓名" value="<?php echo $Skey; ?>">　
            <input name="Skey2" type="text" maxlength="25" class="input size2 W200" placeholder="按客户UID/昵称/姓名/手机号码" value="<?php echo $Skey2; ?>">　
            <script>nulltext='性别';zeai_cn__CreateFormItem('select','sex','<?php echo $sex; ?>','class="size2 SW_edu picmiddle"',sex_ARR);</script>　
            <button type="submit" class="btn size2 QING"><i class="ico">&#xe6c4;</i> 筛选</button>
        </form>
        <div class="rbox"><img src="images/!.png" width="14" height="14" valign="middle"> <font style="vertical-align:middle;color:#999">新增外呼记录后，在此列表将不会出现</font></div>
    </div>
    <!---->
	<?php
    if ($total <= 0 ) { ?>
  		<div class='nodataico'><i></i>暂无分配客户</div>
        <?php
    } else {
        $page_skin=2;$pagemode=3;$pagesize=$_ADM['admPageSize'];require_once ZEAI.'sub/page.php';?>
        <table class="tablelist">
        <form id="www_zeai_cn_FORM" method="get" action="<?php echo SELF; ?>">
        <tr>
        <th width="30"><input type="checkbox" id="checkboxall1" class="checkskin checkboxall"><label for="checkboxall1" class="checkskin-label"><i class="i1"></i></label></th>
        <th width="120">头像/UID/昵称</th>
        <th width="11" align="left">&nbsp;</th>
        <th width="120" align="left">基本资料</th>
        <th width="222" align="left">工作地区/户籍地区</th>
        <th width="111" align="left">手机</th>
        <th align="left">&nbsp;</th>
        <th width="150" align="left">所属门店/服务红娘</th>
        <th width="100" align="center">操作</th> 
        <th width="22" align="left">&nbsp;</th>
        </tr>
        <?php
        for($i=1;$i<=$pagesize;$i++) {
            $rows = $db->fetch_array($rt,'name');
            if(!$rows) break;
            $id = $rows['id'];
            $uid = $id;
			
            $agentid   = intval($rows['agentid']);
            $admid     = intval($rows['admid']);
            $hnid      = intval($rows['hnid']);
            $hnid2     = intval($rows['hnid2']);
            $admtime   = intval($rows['admtime']);
            $admname   = dataIO($rows['admname'],'out');
            $hnname    = dataIO($rows['hnname'],'out');
            $hnname2   = dataIO($rows['hnname2'],'out');
            $agenttitle = dataIO($rows['agenttitle'],'out');
            $agenttitle = (!empty($agenttitle))?'<font class="C999">门店：</font>'.$agenttitle.'<br>':'';
			
			$areatitle = dataIO($rows['areatitle'],'out');
			$area2title = dataIO($rows['area2title'],'out');

            $sex = $rows['sex'];
            $grade = $rows['grade'];
			$photo_s  = $rows['photo_s'];
            $truename = trimhtml(dataIO($rows['truename'],'out'));
            $mob      = dataIO($rows['mob'],'out');		
            $nickname = trimhtml(dataIO($rows['nickname'],'out'));
            $birthday  = $rows['birthday'];
            $age   = (@getage($birthday)<=0)?'':@getage($birthday).'岁';
            $edu   = udata('edu',intval($rows['edu']));
            $love  = udata('love',intval($rows['love']));
			$photo_s_url = (!empty($photo_s))?UP.$photo_s:RES.'photo_s'.$sex.'.png';
        ?>
        <tr id="tr<?php echo $id;?>">
            <td width="30" height="60"><input type="checkbox" name="list[]" value="<?php echo $id; ?>" uid="<?php echo $uid; ?>" id="id<?php echo $id; ?>" class="checkskin"><label for="id<?php echo $id; ?>" class="checkskin-label"><i class="i1"></i></label>
            </td>
          <td width="120" class="padding10">
          
            <a href="<?php echo Href('crm_u',$uid);?>&iframenav=1" class="photo_ss"><img src="<?php echo $photo_s_url; ?>" class="photo_s"></a>
            <a href="<?php echo Href('crm_u',$uid);?>&iframenav=1" class="photo_ss"><?php echo uicon($sex.$grade);?><?php echo $uid;?></a><?php if(!empty($rows['nickname']))echo "</br><font class='uleft'>".$nickname."</font>";?>
            
          </td>
          <td width="11" align="left">&nbsp;</td>
          <td width="120" align="left"  class="lineH200">
             <?php if (!empty($truename)){?><font class="C999">姓名：</font><?php echo $truename;?><br><?php }?>
            <font class="C999">年龄：</font><?php echo $age.'('.substr($birthday,0,4).')';?><br>
            <?php if (!empty($love)){?><font class="C999">婚况：</font><?php echo $love;?><br><?php }?>
            <?php if (!empty($edu)){?><font class="C999">学历：</font><?php echo $edu;?><?php }?>
          </td>
          <td width="222" align="left" class="lineH200">
            <div><?php echo (!empty($areatitle))?'<font class="C999">地区：</font>'.$areatitle:''; ?></div><div><?php echo (!empty($area2title))?'<font class="C999">户籍：</font>'.$area2title:''; ?></div>    </td>
          <td width="111" align="left" class="lineH200 padding15"><?php echo $mob;?></td>
          <td align="left" class="lineH200 padding15">&nbsp;</td>
          <td width="150" align="left" class="lineH200 padding15">
            <?php echo $agenttitle;?>
            <?php $adm_str = ($admtime>0)?'认领':'录入';?>
            <?php if(!empty($admid)){echo '<font class="C999">'.$adm_str.'：</font>'.$admname.' <font class="C999">ID:'.$admid.'</font>';}?>
            <?php if(!empty($hnid)){echo '<br><font class="C999">售前：</font>'.$hnname.' <font class="C999">ID:'.$hnid.'</font>';}?>
            <?php if(!empty($hnid2)){echo '<br><font class="C999">售后：</font>'.$hnname2.' <font class="C999">ID:'.$hnid2.'</font>';}?>
          </td>
          <td width="100" height="60" align="left" class="lineH200 "><a class="btn size2" onClick="zeai.iframe('【<?php echo $uid;?>】外呼跟进记录','crm_talk_gj'+zeai.ajxext+'submitok=add&uid=<?php echo $uid;?>',700,430)"><i class="ico">&#xe622;</i> 新增外呼</a></td>
          <td width="22" align="left" >&nbsp;</td>
          </tr>
        <?php } ?>
        </form>
    </table>
    <?php }?>
    <!---->
</div>


<?php if ($total > 0 ) {?>
<div class="listbottombox">
  <!--   <input type="checkbox" id="checkboxall2" class="checkskin checkboxall"><label for="checkboxall2" class="checkskin-label"><i class="i1"></i></label>　
   <button type="button" id="btndellist" class="btn size2 HEI2 disabled action">批量删除</button>　-->
    <input type="hidden" name="submitok" id="submitok" value="" />
    <?php echo '<div class="pagebox FR">'.$pagelist.'</div>'; ?>
</div>
<script>
var bg = '<?php echo $_Style['list_bg']; ?>',overbg = '<?php echo $_Style['list_overbg']; ?>',selectbg = '<?php echo $_Style['list_selectbg']; ?>';
</script>
<script src="js/zeai_tablelist.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<?php }?>
<script src="laydate/laydate.js"></script><script>lay('#version').html('-v'+ laydate.v);
laydate.render({elem: '#sDATE1'});
laydate.render({elem: '#sDATE2'});
</script>
<?php require_once 'bottomadm.php';?>